package com.leyou.search.web;


import com.leyou.search.dto.SearchRequest;
import com.leyou.search.entity.Goods;
import com.leyou.search.service.IndexService;
import com.leyou.search.service.SearchService;
import com.leyou.starter.elastic.entity.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import reactor.core.publisher.Mono;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("goods")
public class SearchController {

    @Autowired
    private IndexService indexService;

    @Autowired
    private SearchService searchService;


    /**
     * todo 自动补全功能
     *
     * @param key
     * @return
     */
    @GetMapping("suggestion")
    public Mono<List<String>> generateSuggest(@RequestParam("key") String key) {

        return searchService.generateSuggest(key);
    }


    /**
     * todo 页面数据的分页查询
     * @param searchRequest
     * @return
     */
    @PostMapping("/list")
    public Mono<PageInfo<Goods>> listGoods(
            @RequestBody SearchRequest searchRequest) {//PageInfo是自定义的com.leyou.starter JAR包中的 类

        return this.searchService.listGoods(searchRequest);
    }

    /**
     * todo 页面搜索过滤条件的获取
     * @param searchRequest
     * @return
     */
    @PostMapping("/filter")
    public Mono<Map<String,List<?>>> listFilter(
            @RequestBody SearchRequest searchRequest) {//PageInfo是自定义的com.leyou.starter JAR包中的 类

        return this.searchService.listFilter(searchRequest);
    }





}
